package com.example.yslapplication;

import com.example.yslapplication.slice.MainAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.ability.IAbilityContinuation;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.IntentParams;
import ohos.bundle.IBundleManager;

import java.util.ArrayList;
import java.util.List;

public class MainAbility extends Ability implements IAbilityContinuation {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setMainRoute(MainAbilitySlice.class.getName());
//        super.setUIContent(ResourceTable.Layout_ability_main);

        requestPermission();
    }

    //申请运行时权限
    private void requestPermission(){
        String[] re = {"ohos.permission.DISTRIBUTED_DATASYNC"};
        List<String> reList = new ArrayList<>();
        for (String str : re) {
            if (verifySelfPermission(str) != IBundleManager.PERMISSION_GRANTED){
                if (canRequestPermission(str))
                    reList.add(str);
            }
        }
        requestPermissionsFromUser(reList.toArray(new String[0]), 0);
    }

    @Override
    public boolean onStartContinuation() {//开始流转
        return true;
    }

    @Override
    public boolean onSaveData(IntentParams intentParams) {
        return true;
    }

    @Override
    public boolean onRestoreData(IntentParams intentParams) {
        return true;
    }

    @Override
    public void onCompleteContinuation(int i) {

    }

    @Override
    public void onRemoteTerminated() {

    }
}
